package com.zwh.rocketmq.demo.transaction;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.interceptor.DefaultTransactionAttribute;

/**
 * @author zwh
 * @date 2024-1-22 14:30
 */
@Service
public class TransactionalUtil {
    @Autowired
    public DataSourceTransactionManager transactionManager;

    public TransactionStatus begin(){
        TransactionStatus transactionStatus  = transactionManager.getTransaction(new DefaultTransactionAttribute());
        return transactionStatus;
    }

    public void commit(TransactionStatus status){
        transactionManager.commit(status);
    }

    public void rollback(TransactionStatus status){
        transactionManager.rollback(status);
    }
}
